<template>
  <el-dialog :visible="visible"
             title="销售"
             @close="visible = false">
    <el-form class="form">
      <el-form-item class="item"
                    label="销售商"
                    :label-width="formLabelWidth">
        <el-input v-model="formData.seller"
                  class="in"
                  autocomplete="off" />
      </el-form-item>
      <el-form-item class="item"
                    label="产品名称"
                    :label-width="formLabelWidth">
        <el-input v-model="formData.productName"
                  class="in"
                  autocomplete="off" />
      </el-form-item>
      <el-form-item class="item"
                    label="单价"
                    :label-width="formLabelWidth">
        <el-input-number v-model="formData.proudctPrice"
                  class="in"
                  autocomplete="off" />
      </el-form-item>
      <el-form-item class="item"
                    label="销售数量"
                    :label-width="formLabelWidth">
        <el-input-number v-model="formData.productNum"
                  class="in"
                  autocomplete="off" />
      </el-form-item>
      <el-form-item class="item"
                    label="销售人员"
                    :label-width="formLabelWidth">
        <el-input v-model="formData.sellStaff"
                  class="in"
                  autocomplete="off" />
      </el-form-item>
      <el-form-item class="item"
                    label="联系方式"
                    :label-width="formLabelWidth">
        <el-input v-model="formData.staffPhone"
                  class="in"
                  autocomplete="off" />
      </el-form-item>
    </el-form>
    <div slot="footer"
         class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary"
                 @click="confirm">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { saveSell } from '@/api/plant/sell'
export default {
  data () {
    return {
      visible: false,
      isUpdate: false,
      formLabelWidth: '100px',
      formData: {
        id: '',
        plantId: '',
        seller: '',
        productName: '',
        proudctPrice: '',
        productNum: 0,
        productQuota: 0,
        sellStaff: '',
        staffPhone: '',
        gmtCreate: ''
      },
    }
  },
  methods: {
    async init (shipping) {
      this.visible = true
      this.formData = {
        id: '',
        plantId: '',
        shippingId: '',
        seller: '',
        productName: '',
        proudctPrice: '',
        productNum: 0,
        productQuota: 0,
        sellStaff: '',
        staffPhone: '',
        gmtCreate: ''
      }
      if (shipping) {
        this.formData.shippingId = shipping.id
        this.formData.plantId = shipping.plantId
        this.formData.productName = shipping.productName
        this.formData.seller = shipping.site
      }
    },
    confirm () {
      saveSell(this.formData).then(response => {
        if (response.statusCode == 20000) {
          this.refresh()
          this.visible = false
          this.$message({
            message: '操作成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '发生错误，操作失败',
            type: 'warning'
          })
        }
      })
    },
    refresh () {
      this.$emit('refresh')
    }
  }
}
</script>

<style>
.form {
  margin-bottom: 20px;
}
</style>
